package com.erp.serviceIMP;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.erp.Resource.Resouce;
import com.erp.dao.RolesDAO;
import com.erp.entity.Roles;
import com.erp.service.RolesServiceDAO;

@Service("rolesService")
public class RolesServiceIMP implements RolesServiceDAO{
	@Autowired
	private RolesDAO rolesMapper;
	
	public RolesDAO getRolesMapper() {
		return rolesMapper;
	}

	public void setRolesMapper(RolesDAO rolesMapper) {
		this.rolesMapper = rolesMapper;
	}

	/**
	 * 加载所有角色
	 * @return 返回list集合
	 */
	public HashMap<String, Roles> findAll(){
		if(Resouce.roleMap == null){
			Resouce.roleMap = new HashMap<String, Roles>();
			List<Roles> rolesList = rolesMapper.findAll();
			for (Roles roles : rolesList) {
				Resouce.roleMap.put(String.valueOf(roles.getId()), roles);
			}
			
		}
		return Resouce.roleMap;
	}
}
